Skip to content

Verify a contract with its inherited members - #21

Open
evertonfraga wants to merge 4 commits into
fix/soundness-auditfrom
feat/inheritance
Open

evertonfraga wants to merge 4 commits into
fix/soundness-auditfrom
feat/inheritance

Conversation

@evertonfraga

@evertonfraga evertonfraga commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A contract is now verified together with what it inherits. Before, contract Child is Base failed to translate (Resolution failed: 'n' is not defined) as soon as it used anything Base declared.

Stacked on #25 (soundness fixes), which is stacked on #23 (per-obligation goldens). Review after those.

feat(translator): verify a contract with its inherited members

  • A contract is verified as the flattening of its bases and itself, in its own context: inherited state variables, functions, modifiers, structs, enums and invariants resolve, and a base's invariants are checked at every entry point. Each contract of the file is still verified on its own as well.
  • Bases are ordered by solc's C3 linearization (linearizedBaseContracts), computed from the is lists.
  • An inherited function calls the most derived override of a virtual function.
  • A function overrides one with the same name and parameter types, data locations aside. A function with the same name but other parameters is an overload, and both stay.
  • A public state variable overrides the base function its getter implements.
  • An obligation of an inherited function names the contract it is checked in: ensures … (in D). The same clause is checked once per contract that inherits it. An inherited assert is still classified strata/assert-fail in SARIF.
  • A base that the file does not define, directly or through another base, is reported for each contract that inherits it.
  • Rejected: a state variable declared again in a derived contract (a base's private one is a different variable).

feat(translator): run base constructors when a derived contract deploys

A derived contract's constructor first runs its base constructors, as solc's legacy code generator does:

  • after the state-variable initializers, outside the derived constructor's modifiers, most base first;
  • each with its own modifiers, in a block that its return exits;
  • with its parameters and locals renamed apart from the derived constructor's;
  • with the arguments that the most derived constructor naming the base gives (constructor() Base(7)). These are evaluated most derived first, so an argument may read the parameters of the constructor that gives it.

Arguments in an inheritance specifier (is Base(7)) are not in the AST the translator reads: those parameters get unknown values of their types.

The implicit constructor that checks a contract's initial state runs base constructors too. A constructor that runs a base constructor using a struct-valued mapping is not verified, and this is reported.

translateFunction's modifier inlining is now inlineModifiers, shared with base constructors.

feat(translator): super.f(…) and Base.f(…) call inherited implementations

  • super.f(…) calls the implementation of f that follows, in the linearization of the contract being verified, the contract the call is written in. That contract is the one defining the function, modifier or base constructor containing the call.
  • Base.f(…) calls the first implementation in Base's own linearization.
  • An overridden implementation that a call reaches, directly or through another one, is emitted as the internal procedure __base_<Contract>_<f>; an unreached one is not emitted.
  • Named arguments bind by name.
  • Rejected: super of an overloaded function, and a call reaching an implementation that uses a struct-valued mapping.

docs: describe inheritance as the translator now verifies it

  • Updates LIMITATIONS.md, FAQ.md and the guide (limitations.md, supported_features.md, overview.md). They had called inheritance both "flattened at the AST level" and "single contract only, no virtual dispatch".
  • Updates CHANGELOG.md.
  • Adds .kiro/specs/strata-solidity-next/requirements.md: REQ-NEXT-SOL-001..025 close GAP-009 except for the cases reported, rejected or read as unknown.

Testing

  • New fixtures, each pairing true and false properties with // Passes / // Refuted / // Not proven comments:
    • inheritance.sol: state, modifiers, internal calls, invariants, virtual dispatch, getter override
    • inheritance_overloads.sol
    • inheritance_constructors.sol: order against modifiers, base modifiers, return, locals, arguments from the derived and from an intermediate constructor, specifier arguments
    • inheritance_linearization.sol: C3 order differs from a depth-first order
    • inheritance_super.sol and inheritance_diamond.sol: super in functions, modifiers and base constructors, Base.f(), named arguments, a contract that does not override
    • inheritance_imported.sol, inheritance_struct_mapping.sol, inheritance_shadowed_state.sol
  • CI=true bash test/run_tests.sh: 77 passed, 0 failed, with z3 4.15.4 and with z3 4.8.12 (CI's version until Pin z3 4.15.4 on CI #26). No existing golden changed.
  • lake test, python3 -m pytest Tools/Solidity/test, lake run pbt-determinism and the docs site build pass.
  • The coherence audit's inheritance probes give a correct or not-proven verdict on every false property. These cover base constructors under modifiers, base-constructor modifiers and return, super in modifiers and base constructors, named super arguments, explicit base calls, super without an override, getter overrides, transitive imported bases, and unreachable implementations.

Not covered

  • A base in another file contributes no members (reported).
  • Arguments of an inheritance specifier, is Base(7), are unknown values.
  • Base constructors run in the legacy order. --via-ir initializes each contract's state variables just before its own constructor.
  • Overloads whose parameters are all integers or addresses (f(uint256) and f(address)) have the same parameter types in the verifier and are rejected, in a single contract too.

solc does not flatten inherited members into a derived contract, so a
contract that used anything its base declared failed to translate
(`Resolution failed: 'n' is not defined`). A contract is now verified as
the flattening of its bases and itself, in its own context: inherited
state variables, functions, modifiers, structs, enums and invariants
resolve, an inherited function calls the most derived override of a
virtual function, and a base's invariants are checked at every entry
point. Each contract of the file is still verified on its own.

- Bases are ordered by solc's C3 linearization.
- A function overrides one with the same name and parameter types (data
  locations aside); an overload stays. A public state variable overrides
  the base function its getter implements.
- An obligation of an inherited function names the contract it is checked
  in, `ensures … (in Fast)`, as the same clause is checked once per
  contract that inherits it. An inherited `assert` is still classified
  `strata/assert-fail` in SARIF.
- A base that the file does not define, directly or through another base,
  is reported for each contract that inherits it.

Rejected for now: a base constructor that does anything, `super`, and a
state variable declared again in a derived contract (a base's private
one is a different variable).
A constructor of a contract with bases now first runs the base
constructors, as solc's legacy code generator does:

- after the state-variable initializers, outside the constructor's own
  modifiers, most base first;
- each with its own modifiers, in a block that its `return` exits, so an
  early return ends that constructor only;
- with its parameters and locals renamed apart from the derived
  constructor's (`__ctor_<Base>_<name>`);
- with the arguments that the most derived constructor naming the base
  gives (`constructor() Base(7)`), evaluated most derived first, so an
  argument may read the parameters of the constructor that gives it. An
  inheritance specifier's arguments (`is Base(7)`) are not in the AST:
  those parameters are unknown values of their types.

The implicit constructor that checks a contract's initial state runs them
too. A constructor that runs a base constructor using a struct-valued
mapping is not verified, as one using it itself is not (reported).

The modifier inlining of `translateFunction` is now `inlineModifiers`,
shared with the base constructors; a function's labels are unchanged.
…ntations

`super.f(…)` calls the implementation of `f` that follows, in the
linearization of the contract being verified, the contract the call is
written in: a function's, a modifier's (the contract defining the
modifier) or a base constructor's. So the same body can call different
implementations in different contracts. `Base.f(…)` calls the first
implementation in Base's own linearization.

An overridden implementation that such a call reaches, directly or
through another one, is emitted as the internal procedure
`__base_<Contract>_<f>` of the contract being verified, with its own
specification; one no call reaches is not. A call that reaches the
implementation the contract keeps calls that procedure. Named arguments
bind by name.

Rejected: `super.f(…)` of an overloaded `f`, and a call reaching an
implementation that uses a struct-valued mapping.

inheritance_linearization.sol pins C3 order through base constructors: a
depth-first order of the base lists runs them in a different order and
gives a different result.
The documentation called inheritance accepted and "flattened at the AST
level" (supported_features.md, REQ-SOL-004/005) and also "single contract
only, no virtual dispatch" (LIMITATIONS.md, GAP-009); FAQ.md and the
overview said Solidity has no dynamic dispatch to model. All now describe
what is verified, what is reported (a base in another file) and what is
rejected or read as unknown.

Adds .kiro/specs/strata-solidity-next/requirements.md, the follow-on spec
CONTRIBUTING.md requires for closing a gap: REQ-NEXT-SOL-001..025 close
GAP-009 except for the cases they report or reject, cite REQ-SOL-004..006,
and leave the baseline unchanged. CHANGELOG.md has an entry.
@evertonfraga
evertonfraga changed the base branch from main to fix/soundness-audit October 23, 2026 16:21
@evertonfraga
evertonfraga added this pull request to stack #28 October 27, 2026 19:24

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant